package com.pshare.artemis.config.service;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.pshare.util.HttpUtils;
import com.pshare.util.SysPropertyUtils;
import com.pshare.util.WXSignUtils;

@Service
public class ConfigService{
	
	private static final Logger logger = Logger.getLogger(ConfigService.class);

	/**
	 * 微信ACCESS_TOKEN
	 */
	
	public void getWXAccessToken() {
		 String appid=SysPropertyUtils.getProperty("wx.appid");
		 String appsecret=SysPropertyUtils.getProperty("wx.appsecret");
		 String host=SysPropertyUtils.getProperty("wx.accesstoken_host");
		 String url=host+"?grant_type=client_credential&appid="+appid+"&secret="+appsecret;
		 JSONObject object=HttpUtils.getJsonInUrlGet(url);
		 String accessToken="";
		 if(object!=null){
			 accessToken=object.getString("access_token");
		 }
		 WXSignUtils.ACCESS_TOKEN=accessToken;
		 logger.info("url="+url+",,,accessToken="+accessToken);
	}
	
}
